
/*
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


%{

#include "config.h"

#include <stdio.h>
#include <string.h>

#include "main.h"

#include "parse.h"
#include "uniqstring.h"

#define MAXSTRING 22*1024


%}

	/* for lint purists according to flex manual */
%option nounput

	/* suppress gcc warning input() defined but not used */
%option noinput

	/* input does not come from a tty. */
%option never-interactive

	/* no yywrap() at end of file */
%option noyywrap

	/* 8-bits scanner */
%option 8bit

	/* generate line number */
%option yylineno


DOTSCHAR	[A-Za-z_\x80-\xFF]
DOTSID		{DOTSCHAR}({DOTSCHAR}|[0-9])*
DOTSNUM		[-]?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))
ISTR		[^\\\"]|\\.|\\\n
STR		\"({ISTR}*)\"
CCS		\/\*[^\*]*\*+([^\*\/][^\*]*\*+)*\/
CCE		\/\/[^\n]*

%%

[\f ]+ { }
[\t] { }
[\n] { }

{CCS} { }
{CCE} { }


{STR}	{
	char *p;
	char c;
	int i;
	char buf[MAXSTRING];
	yytext[strlen(yytext)-1] = '\0'; 
	p = yytext;
	i = 0;
	memset (buf,0,MAXSTRING);
	while (*p++)
	{
	 if (*p == '\\') {
	  p++;
	  if (*p == 'n') {
	   c = '\n';
          } else if (*p == ' ') {
           c = ' ';
          } else if (*p == 'l') {
           c = ' ';
          } else if (*p == '\n') {
           c = '\n';
	  } else if (*p == '"') {
	   c = '"';
	  } else {
	   buf[i] = '\\';
	   i = i + 1;
	   if (i == MAXSTRING -1) {
	    break;
	   }
	   c = *p;
	  }
	 } else {
	  c = *p;
	 }
	 if (c) {
	   buf[i] = c;
	 }
	 if (i == MAXSTRING -1) {
	  break;
	 }
	 if (c) {
	   i++;
	 }
	}
	laststring = uniqstring(buf);
	return (DOT_STRING); 
	}

{DOTSNUM} { lastnum = uniqstring (yytext); return (DOT_NUM); }

"--" { return (DOT_UEDGE); }
"->" { return (DOT_DEDGE); }
"{" { return ('{'); }
"}" { return ('}'); }
"[" { return ('['); }
"]" { return (']'); }
"," { }
";" { }
":" { return (':'); }
"=" { return ('='); }


"black" { return (DOT_BLACK); }
"blue" { return (DOT_BLUE); }
"color" { return (DOT_COLOR); }
"constraint" { return (DOT_CONSTRAINT); }
"dashed" { return (DOT_DASHED); }
"digraph" { return (DOT_DIGRAPH); }
"dotted" { return (DOT_DOTTED); }
"edge" { return (DOT_EDGEDEFAULT); }
"false" { return (DOT_FALSE); }
"filled" { return (DOT_FILLED); }
"fillcolor" { return (DOT_FILLCOLOR); }
"graph" { return (DOT_GRAPH); }
"green" { return (DOT_GREEN); }
"invis" { return (DOT_INVIS); }
"label" { return (DOT_LABEL); }
"labeljust" { return (DOT_LABELJUST); }
"lightblue" { return (DOT_LIGHTBLUE); }
"lightgrey" { return (DOT_LIGHTGREY); }
"lightpink" { return (DOT_LIGHTPINK); }
"Mdiamond" { return (DOT_MDIAMOND); }
"normal" { return (DOT_NORMAL); }
"node" { return (DOT_NODEDEFAULT); }
"overlap" { return (DOT_OVERLAP); }
"penwidth" { return (DOT_PENWIDTH); }
"record" { return (DOT_RECORD); }
"red" { return (DOT_RED); }
"shape" { return (DOT_SHAPE); }
"solid" { return (DOT_SOLID); }
"strict" { return (DOT_STRICT); }
"style" { return (DOT_STYLE); }
"subgraph" { return (DOT_SUBGRAPH); }
"true" { return (DOT_TRUE); }
"weight" { return (DOT_WEIGHT); }
"white" { return (DOT_WHITE); }

{DOTSID} { lastid = uniqstring (yytext); return (DOT_ID); }




. { return (yytext[0]); }

%%

void dotlexinit (FILE *f)
{
 if (f) {}
 return;
}

void dotlexreset (void)
{
 dotlex_destroy ();
 return;
}

int dotlex_lineno (void)
{
 return (yylineno);
}

/* End */
